<?php
session_start();
include 'DBconnect.php';
include "action.php";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <form method="get" action="<?= $_SERVER['PHP_SELF']; ?>">
            <input type="text" name="input" x-webkit-speech/>
            <input type="submit" style="display:none;"/>

        </form>

        <?php
        if (isset($_POST['login'])) {
            if (!empty($_POST['username']) && !empty($_POST['pw'])) {
                $check = "SELECT id FROM user WHERE username='" . $_POST['username'] . "' AND pw='" . md5($_POST['pw']) . "'";
                $check_result = mysqli_query($c, $check);
                if (!mysqli_num_rows($check_result)) {
                    echo "<script type='text/javascript'>window.location='index.php';</script>";
                }
            } else {
                echo "<script type='text/javascript'>window.location='index.php';</script>";
            }
            while ($row = mysqli_fetch_assoc($check_result)) {
                $_SESSION['id'] = $row['id'];
            }
        }




        $action = new action();
        $action->c = $c;

        if (isseT($_GET['input'])) {
            $action->take($_GET['input']);
        }
        ?>



    </body>
</html>
